#include "main.h"

cr_state *state;

int main(int argc, char **argv) {
    /* start SDL */
    uint32_t flags = SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS;
    if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
        fprintf(stderr, "SDL_Init error: %s\n", SDL_GetError());
        return EXIT_FAILURE;
    }

    int window_w, window_h, font_size;
    char *font;
    parse_user_options(argc, argv, &window_w, &window_h, &font, &font_size);

    /* init from init.c (graphics + game logic) */
    state = init(window_w, window_h, font, font_size);
    //state = init(NULL, WINDOW_W, WINDOW_H, FONTSIZE);

    /* when program exits, execute cleanup */
    atexit(cleanup);

    int quit = 0;
    while (!quit) {
        pre_render(&state->renderer, &state->display);
        update_cmus_rg(state);
        render(&state->renderer, &state->display, &state->render_change, state->drawables, state->drawextras, state->root);
        get_input(state->update, state->root, &state->window_w, &state->window_h, &state->border);
        /* set to around 60fps (1000 ms/ 60 fps = 1/16 ms^2/frame) */
        SDL_Delay(16);
    }

    return EXIT_SUCCESS;
}